<template>
	<view class="content-container">
		<uni-forms :value="formData" :rules="rules" ref="form" label-width="100">
			<uni-forms-item label="姓名:" name="trueName" required>
				<uni-easyinput type="text" v-model="formData.trueName" placeholder="请输入姓名" style="width:100%"/>
			</uni-forms-item>
			<uni-forms-item label="性别:" name="enumSex" required>
				<evan-radio v-model="formData.enumSex" label="0" style="margin-right: 30px">男</evan-radio>
				<evan-radio v-model="formData.enumSex" label="1">女</evan-radio>
			</uni-forms-item>
			<uni-forms-item label="联系方式:" name="mobileNumber" required>
				<uni-easyinput type="text" v-model="formData.mobileNumber" placeholder="请输入联系方式" style="width:100%"/>
			</uni-forms-item>
			<uni-forms-item label="年龄:" name="age" required>
				<uni-easyinput type="text" v-model="formData.age" placeholder="请输入年龄" style="width:100%"/>
			</uni-forms-item>
			<uni-forms-item label="生日:" name="birthday" required>
				<uni-datetime-picker type="date" return-type="string" v-model="formData.birthday" style="width:100%"></uni-datetime-picker>
			</uni-forms-item>
			<uni-forms-item label="收入评估:" name="income" required>
				<ld-select :list="incomeTypes"
					style="width: 100%; font-size: 14px;"
					label-key="itemName" value-key="itemValue"
					placeholder="请选择收入评估"
					clearable
					v-model="formData.income"
					@change="selectChange"
				></ld-select>
			</uni-forms-item>
			<uni-forms-item label="家庭状况:" name="family" required>
				<uni-easyinput type="text" v-model="formData.family" placeholder="请输入家庭状况" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="职业工作:" name="positionName" required>
				<uni-easyinput type="text" v-model="formData.positionName" placeholder="请输入职业工作" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="居住区域:" name="liveAddress" required>
				<uni-easyinput type="text" v-model="formData.liveAddress" placeholder="请输入居住区域" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="生活区域:" name="lifeAddress" required>
				<uni-easyinput type="text" v-model="formData.lifeAddress" placeholder="请输入生活区域" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="现住小区:" name="nowHouse" required>
				<uni-easyinput type="text" v-model="formData.nowHouse" placeholder="请输入现住小区" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="到访项目:" name="visitProject" required>
				<uni-easyinput type="text" v-model="formData.visitProject" placeholder="请输入到访项目" style="width: 100%"/>
			</uni-forms-item>
			<uni-forms-item label="到访日期:" name="visitDate" required>
				<uni-datetime-picker type="date" return-type="string" v-model="formData.visitDate" style="width:100%"></uni-datetime-picker>
			</uni-forms-item>
			<uni-forms-item label="录入日期:" name="recordDate" required>
				<uni-datetime-picker type="date" return-type="string" v-model="formData.recordDate" style="width:100%"></uni-datetime-picker>
			</uni-forms-item>
			<uni-forms-item label="置业顾问:" name="counselor" required>
				<uni-easyinput type="text" v-model="formData.counselor" placeholder="请输入置业顾问" style="width: 100%"/>
			</uni-forms-item>
			
			<uni-forms-item label="成交项目:" name="dealProject">
				<uni-easyinput type="text" v-model="formData.dealProject" placeholder="请输入成交项目" style="width: 100%"/>
			</uni-forms-item>
			
			<uni-forms-item label="成交房号:" name="dealRoom">
				<uni-easyinput type="text" v-model="formData.dealRoom" placeholder="请输入成交房号" style="width: 100%"/>
			</uni-forms-item>
			
			<uni-forms-item label="成交面积:" name="dealArea">
				<uni-easyinput type="text" v-model="formData.dealArea" placeholder="请输入成交面积" style="width: 100%"/>
			</uni-forms-item>
			
			<uni-forms-item label="成交日期:" name="dealDate">
				<uni-datetime-picker type="date" return-type="string" v-model="formData.dealDate" style="width:100%"></uni-datetime-picker>
			</uni-forms-item>
			
			<uni-forms-item label="备注:" name="remark">
				<uni-easyinput type="text" v-model="formData.remark" placeholder="请输入备注" style="width: 100%"/>
			</uni-forms-item>
		
			<button type="primary" @click="submit">提交</button>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					dealProject: "",
					dealRoom: "",
					dealArea: "",
					dealDate: "", 
					remark: "",
					trueName: "",
					mobileNumber: "",
					age: "",
					birthday: "",
					family: "",
					positionName: "",
					liveAddress: "",
					lifeAddress: "",
					nowHouse: "",
					visitProject: "",
					visitDate: "",
					recordDate: "",
					counselor: "",
					enumSex: '0',
					income: ''
				},
				incomeTypes: [],
				rules: {
					// 对name字段进行必填验证
					trueName: { rules: [
						{ required: true, errorMessage: '此项为必填项'}
					]},
					mobileNumber: { rules: [
						{ required: true, errorMessage: '此项为必填项'}
					]},
					age: { rules: [
						{ required: true, errorMessage: '此项为必填项'}
					]},
					birthday: { rules: [
						{ required: true, errorMessage: '此项为必填项'}
					]},
					income: { rules: [
						{ required: true, errorMessage: '此项为必填项'}
					]},
					family: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					positionName: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					liveAddress: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					lifeAddress: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					nowHouse: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					visitProject: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					visitDate: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					recordDate: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]},
					counselor: { rules: [
						{ required: true, errorMessage: '此项为必填项' }
					]}
				}
			};
		},
		mounted() {
			this.getIncomeTypes();
		},
		methods: {
			getIncomeTypes() {
				this.$api.globalUtil.requestAjax({
					url: "/api/sysEnumDictionary/getListByPage",
					method: "POST",
					data: {
						queryStr: 'system_data_income_type',
					    pageNum: 1,
						recordNum: 200
					}
				}).then(res => {
					this.incomeTypes = res.data;
				});
			},
			
			selectChange(val){
				this.formData.income = val
			},
			
			// 触发提交表单
			submit() {
				this.$refs.form.submit().then(response=>{
					this.$api.globalUtil.requestAjax({
						url: "/api/sysSellerUser/create",
						method: "POST",
						data: this.formData
					}).then(res => {
						this.$api.msg(res.message || '创建成功', 3000);
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/dash/dash'
							});
						}, 500);
					});
				}).catch(err =>{
					// console.log('表单错误信息：', err);
				})
			}
		}
	}
</script>

<style lang="scss">
	.content-container {
		padding: 20px 16px;
	}
	
	::v-deep .uni-forms-item__content {
		display: flex;
		align-items: center;
	}
	
	::v-deep uni-input {
		font-size: 14px;
	}
	
	::v-deep .input, .input {
		padding: 2px 10px !important;
	}
	
	.evan-radio__label {
		font-size: 14px !important;
	}
</style>
